import React, { Component } from 'react'

export default class Item extends Component {
    handleCheck = (id) => {
        return (e) => {
            console.log(id, e.target.checked)
            this.props.updateTodo(id,e.target.checked)
        }
    }
    handleDelete = (id) =>{
        return () => {
            if(window.confirm('是否删除此项')){
                this.props.deleteTodo(id)
            }
        }
    }
    render() {
        const { id, name, done } = this.props
        return (
            <div>
                <input type="checkbox" checked={done} onChange={this.handleCheck(id)} />
                <span>{name}</span>
                <button onClick={this.handleDelete(id)}>删除</button>
            </div>
        )
    }
}
